#define INF 0x3f3f3f3f
class Solution {
public:
  int minSessions(vector<int>& tasks, int sessionTime) {
    int n = tasks.size();
    int N = 1 << n;
    vector<int> dp(N, INF);
    dp[0] = 0;
    vector<int> sum(N, 0);
    for (int i = 0; i < N; ++i) {
      for (int k = 0; k < n; ++k) {
        if (i & (1 << k)) sum[i] += tasks[k];
      }
      if (sum[i] <= sessionTime) dp[i] = 1; 
    }
    for(int i=1;i<N;i++)
    {
        for(int j=(i-1)&i;j ;j=(j-1)&i)
        {
            if(sum[j]<=sessionTime) 
            {
                dp[i]=min(dp[i],dp[i^j]+1);
            }
        }
    }
    return dp[N-1];
  }
};